#include <stdio.h>
#include <stdlib.h>

/* http://code.google.com/codejam/contest/351101/dashboard#s=p0 */

/* void qsort(void *array, size_t nmember, size_t size, int (*cmp)(const void *, const void *)) */

typedef struct {
    int index;
    int i;
} pair;

int cmp(const void *elem1, const void *elem2)
{
    pair *p1 = (pair *)elem1;
    pair *p2 = (pair *)elem2;

    return p1->i - p2->i;
}

int main(int argc, char ** argv)
{
    if(argc < 4) {
        fprintf(stderr, "usage: %s [c] [n] [i1 i2 ...]\n", argv[0]);
        return -1;
    }

    int c = atoi(argv[1]);
    int n = atoi(argv[2]);
    int len = argc - 3;
    if(len != n) {
        fprintf(stderr, "number of elements is not equal to inputed", argv[0]);
        return -1;
    }

    pair *pairs = (pair *)malloc(len * sizeof(pair));
    int i;
    for(i = 0;i < len; i++) {
        pairs[i].index = i+1;
        pairs[i].i = atoi(argv[i+3]);
    }

    qsort(pairs, len, sizeof(pair), cmp);

    //for(i = 0; i < len;i++) {
        //printf("%d - %d\n", pairs[i].index, pairs[i].i);
    //}

    pair key;
    int is_found = 0;
    int idx1, idx2;
    for(i = 0;i < len;i++) {
        key.i = c - pairs[i].i;
        pair *result = bsearch(&key, pairs+i+1, len-i-1, sizeof(pair), cmp);
        if(result) {
            is_found = 1;
            idx1 = pairs[i].index;
            idx2 = result->index;
            //printf("%d[%d] + %d[%d] = %d\n", pairs[i].i, pairs[i].index, result->i, result->index, c);
            break;
        }
    }

    if(is_found) {
        if(idx1 > idx2) {
            int tmp = idx1;
            idx1 = idx2;
            idx2 = tmp;
        }

        printf("output: %d %d\n", idx1, idx2);
    } else {
        printf("error: no pair!\n");
    }

    free(pairs);
}
